package com.sanjiahantang.youjiarole.module.common.presenters;

import android.content.Context;

import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseMvpPresenter;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.module.article.beans.ArticleResponseBean;
import com.sanjiahantang.youjiarole.module.article.models.IArticleModel;
import com.sanjiahantang.youjiarole.module.article.models.impl.ArticleModel;
import com.sanjiahantang.youjiarole.module.common.beans.HelpBean;
import com.sanjiahantang.youjiarole.module.common.beans.RichTextBean;
import com.sanjiahantang.youjiarole.module.common.models.IUserModel;
import com.sanjiahantang.youjiarole.module.common.models.impl.UserModel;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zy on 2017/10/17.
 */

public class WebPresenter extends BaseMvpPresenter<BaseView> {

    private IUserModel userModel;
    private IArticleModel articleModel;

    public WebPresenter() {
        userModel = new UserModel();
        articleModel = new ArticleModel();
    }

    public void loadHelpArticle(Context context, int id, final BaseView.OnLoadListener onLoadListener) {
        Map<String, String> param = new HashMap<>();
        param.put("articleNo", String.valueOf(id));
        userModel.loadHelpArticle(context, param, new CallBack<HelpBean.Item>() {

            @Override
            public void onSuccess(HelpBean.Item response, Context context, Object tag) {
                if (mView == null) return;
                mView.hideProgress();
                onLoadListener.onLoad(response.getArContent());
            }

            @Override
            public void onFailure(String message) {
                if (mView == null) return;
                mView.hideProgress();
            }
        });
    }

    public void loadMatchCenterArticle(Context context, int id, final BaseView.OnLoadListener listener) {
        Map<String, String> param = new HashMap<>();
        param.put("articleNo", String.valueOf(id));
        articleModel.findArTrainByIdRole(context, param, new CallBack<ArticleResponseBean>() {

            @Override
            public void onSuccess(ArticleResponseBean response, Context context, Object tag) {
                if (mView == null) return;
                mView.hideProgress();
                if (response.getCode() == RESPONSE_CODE_SUC) {
                    listener.onLoad(response.getData());
                }

            }

            @Override
            public void onFailure(String message) {
                if (mView != null)
                    mView.hideProgress();
            }
        });
    }

    //    富文本请求
    public void loadRichTextCenterArticle(Context context, String id, final BaseView.OnLoadListener listener) {
        Map<String, String> map = new HashMap<>();
        map.put("snId", id);
        articleModel.findNoticeInfoById(context, map, new CallBack<RichTextBean>() {
            @Override
            public void onSuccess(RichTextBean response, Context context, Object tag) {
                if (mView == null) return;
                mView.hideProgress();
                if (response.getCode() == RESPONSE_CODE_SUC) {
                    listener.onLoad(response.getData());
                }
            }

            @Override
            public void onFailure(String message) {
                if (mView != null)
                    mView.hideProgress();
            }
        });
    }
}
